﻿(function () {
    var skillsFactory = function ($http, $q) {
        var factory = {};

        factory.getSkills = function (id) {
            var defered = $q.defer();

            $http({
                method: 'GET',
                url: '/api/SkillsBySkillType/' + id
            }).success(function (data, status, headers, config) {
                //$log.info(data, status, headers(), config);
                defered.resolve(data);
            }).error(function (data, status, headers, config) {
                //$log.warn(data, status, headers(), config);
                defered.reject(status);
            });
            return defered.promise;
        };

        factory.addSkill = function (skill) {
            var defered = $q.defer();

            $http.post('/api/Skill', skill)
            .success(function (data, status, headers, config) {
                //$log.info(data, status, headers(), config);
                defered.resolve(data);
            }).error(function (data, status, headers, config) {
                //$log.warn(data, status, headers(), config);
                defered.reject(status);
            });
            return defered.promise;
        };

        factory.updateSkill = function (skill) {
            var defered = $q.defer();

            $http.put('/api/Skill/' + skill.id, skill)
            .success(function (data, status, headers, config) {
                //$log.info(data, status, headers(), config);
                defered.resolve(data);
            }).error(function (data, status, headers, config) {
                //$log.warn(data, status, headers(), config);
                defered.reject(status);
            });
            return defered.promise;
        };

        return factory;
    };

    skillsFactory.$inject = ['$http', '$q'];
    angular.module('app').factory('skillsFactory', skillsFactory);
}());